<script type="text/javascript">
$(function(){
	var pg = App.macRpc.nodeIndex.ui, pp = pg.params,
		data = null,
		nodeGd = pg.seek('nodeGd'),
		infoPl = pg.children('.infoPl');

	nodeGd.mac('grid', {
		key: 'key',
		cols : [{
			field: 'key', title : 'IP地址', width: 180
// 			render: function(r){
// 				return $('<a href="#mac-rpc?addr='
// 					+ r.key + '"></a>').click(function(){
// 					showDetail(r);
// 					return false;
// 				}).append(r.key);
// 			}
		},{
			field: 'version', title : '上次更新时间', width: 180,
			render: function(r){
				return new Date(r.version.time).format('yyyy-MM-dd HH:mm:ss.S');
			}
		}],
		pagerLength: 10,
		onRowClick: function(){
			nodeGd.find('.tr').removeClass('selected');
			var r = nodeGd.selected = $(this).addClass('selected');
			window.location = '#mac-rpc/node?addr=' + r.attr('name');
			return false;
		}
	});
	
	function init(o,s) {		
		data = o;
		var l = [], d = o.reg;
		for (var k in d) {
			if(s == null){
				l.push(d[k]);
			}else{
				if(k.indexOf(s) >= 0){
					l.push(d[k]);
				}
			}
		}
		nodeGd.loadData(l);
		var a = App.getHashParam('addr'), g = nodeGd;
		if (a) {
			nodeGd.selected = nodeGd.find('.tr[name="'
				+ a + '"]').addClass('selected');
			showDetail(d[a]);
		}
	}
	
	function showDetail(o){
		App.show({
			ctx : 'macRpc',
			action : 'nodeMain',
			params : { reg: o, all: data }
		}, $.noop, infoPl);
	}
	
	function adjust(){
		var p = pg.parent(), h = p.height() - 2, w = p.width();
		pg.width(w).height(h);
		nodeGd.parent().height(h - 16);
		nodeGd.adjust();
		infoPl.height(h - 8).width(w - nodeGd.width() - 16);
	}
	$(window).resize(adjust);
	adjust();
	
	var w = mac.wait('Loading');

	initdata(null);
	
	function initdata(b){
		$.get(App.ctx + '/mac/rpc/info.do', {
			addr: App.getHashParam('addr'),
			r: Math.random()
		}, function(rs) {
			w.close();
			var ro = mac.eval(rs);
			if (ro.success) {
				init(ro.data,b);
			} else {
				mac.alert(ro.data, ro.params);
			}
		});
	}
	
	pg.seek('srchBtn').click(function(e) {
		initdata($(pg.seek('key')).val());
	});
	
	pg.seek('key').keydown(function(e) {
		if (e.keyCode == 13)
			initdata($(pg.seek('key')).val());
	});
	
});
</script>
<div class="left fl">
<div class="head">
	&nbsp;&nbsp; IP地址：<input type="text" name="key" />
	<button name="srchBtn">查找</button>
</div>
	<div class="body">
		<div class="grid" name="nodeGd"></div>
	</div>
</div>
<div class="infoPl"></div>